<?php

/**
 * Application Models
 *
 * @package Application_Model
 * @subpackage Model
 * @author <SONIA ZRIBI>
 * @copyright ZF model generator
 * @license http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * Abstract class for models
 */
require_once 'ModelAbstract.php';

/**
 * 
 *
 * @package Application_Model
 * @subpackage Model
 * @author <SONIA ZRIBI>
 */
class Application_Model_Course extends Application_Model_ModelAbstract
{

    /**
     * Database var type int(11)
     *
     * @var int
     */
    protected $_Idcourse;

    /**
     * Database var type varchar(45)
     *
     * @var string
     */
    protected $_Coursename;

    /**
     * Database var type int(11)
     *
     * @var int
     */
    protected $_SemestreIdsemestre;


    /**
     * Parent relation fk_courselot_semestre1
     *
     * @var Application_Model_Semestre
     */
    protected $_Semestre;


    /**
     * Dependent relation fk_tuteur_has_courselot_courselot1
     * Type: One-to-Many relationship
     *
     * @var Application_Model_TuteurHasCourselot
     */
    protected $_TuteurHasCourselot;

    /**
     * Sets up column and relationship lists
     */
    public function __construct()
    {
        parent::init();
        $this->setColumnsList(array(
            'idcourse'=>'Idcourse',
            'coursename'=>'Coursename',
            'semestre_idsemestre'=>'SemestreIdsemestre',
        ));

        $this->setParentList(array(
            'FkCourselotSemestre1'=> array(
                    'property' => 'Semestre',
                    'table_name' => 'Semestre',
                ),
        ));

        $this->setDependentList(array(
            'FkTuteurHasCourselotCourselot1' => array(
                    'property' => 'TuteurHasCourselot',
                    'table_name' => 'TuteurHasCourselot',
                ),
        ));
    }

    /**
     * Sets column idcourse
     *
     * @param int $data
     * @return Application_Model_Course
     */
    public function setIdcourse($data)
    {
        $this->_Idcourse = $data;
        return $this;
    }

    /**
     * Gets column idcourse
     *
     * @return int
     */
    public function getIdcourse()
    {
        return $this->_Idcourse;
    }

    /**
     * Sets column coursename
     *
     * @param string $data
     * @return Application_Model_Course
     */
    public function setCoursename($data)
    {
        $this->_Coursename = $data;
        return $this;
    }

    /**
     * Gets column coursename
     *
     * @return string
     */
    public function getCoursename()
    {
        return $this->_Coursename;
    }

    /**
     * Sets column semestre_idsemestre
     *
     * @param int $data
     * @return Application_Model_Course
     */
    public function setSemestreIdsemestre($data)
    {
        $this->_SemestreIdsemestre = $data;
        return $this;
    }

    /**
     * Gets column semestre_idsemestre
     *
     * @return int
     */
    public function getSemestreIdsemestre()
    {
        return $this->_SemestreIdsemestre;
    }

    /**
     * Sets parent relation SemestreIdsemestre
     *
     * @param Application_Model_Semestre $data
     * @return Application_Model_Course
     */
    public function setSemestre(Application_Model_Semestre $data)
    {
        $this->_Semestre = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['idsemestre'];
        }

        $this->setSemestreIdsemestre($primary_key);

        return $this;
    }

    /**
     * Gets parent SemestreIdsemestre
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Semestre
     */
    public function getSemestre($load = true)
    {
        if ($this->_Semestre === null && $load) {
            $this->getMapper()->loadRelated('FkCourselotSemestre1', $this);
        }

        return $this->_Semestre;
    }

    /**
     * Sets dependent relations fk_tuteur_has_courselot_courselot1
     *
     * @param array $data An array of Application_Model_TuteurHasCourselot
     * @return Application_Model_Course
     */
    public function setTuteurHasCourselot(array $data)
    {
        $this->_TuteurHasCourselot = array();

        foreach ($data as $object) {
            $this->addTuteurHasCourselot($object);
        }

        return $this;
    }

    /**
     * Sets dependent relations fk_tuteur_has_courselot_courselot1
     *
     * @param Application_Model_TuteurHasCourselot $data
     * @return Application_Model_Course
     */
    public function addTuteurHasCourselot(Application_Model_TuteurHasCourselot $data)
    {
        $this->_TuteurHasCourselot[] = $data;
        return $this;
    }

    /**
     * Gets dependent fk_tuteur_has_courselot_courselot1
     *
     * @param boolean $load Load the object if it is not already
     * @return array The array of Application_Model_TuteurHasCourselot
     */
    public function getTuteurHasCourselot($load = true)
    {
        if ($this->_TuteurHasCourselot === null && $load) {
            $this->getMapper()->loadRelated('FkTuteurHasCourselotCourselot1', $this);
        }

        return $this->_TuteurHasCourselot;
    }

    /**
     * Returns the mapper class for this model
     *
     * @return Application_Model_Mapper_Course
     */
    public function getMapper()
    {
        if ($this->_mapper === null) {
            $this->setMapper(new Application_Model_Mapper_Course());
        }

        return $this->_mapper;
    }

    /**
     * Deletes current row by deleting the row that matches the primary key
     *
	 * @see Application_Model_Mapper_Course::delete
     * @return int|boolean Number of rows deleted or boolean if doing soft delete
     */
    public function deleteRowByPrimaryKey()
    {
        if ($this->getIdcourse() === null) {
            throw new Exception('Primary Key does not contain a value');
        }

        return $this->getMapper()
                    ->getDbTable()
                    ->delete('idcourse = ' .
                             $this->getMapper()
                                  ->getDbTable()
                                  ->getAdapter()
                                  ->quote($this->getIdcourse()));
    }
}
